﻿using RuoYi.Framework.Extensions;

namespace RuoYi.Common.Data;

public class PageDomain
{
    /// <summary>
    /// 当前记录起始索引
    /// </summary>
    public int PageNum { get; set; }

    /// <summary>
    /// 每页显示记录数
    /// </summary>
    public int PageSize { get; set; }

    /// <summary>
    /// 排序列名
    /// </summary>
    public string? OrderByColumn { get; set; }

    /// <summary>
    /// 排序方向（ascending/descending）
    /// </summary>
    public string? IsAsc { get; set; }

    /// <summary>
    /// 是否为升序排序
    /// </summary>
    public bool IsAscending => string.Equals(IsAsc, "ascending", StringComparison.OrdinalIgnoreCase);
     
    /// <summary>
    /// 排序字段属性名
    /// </summary>
    public string? PropertyName { get; set; }
     
    /// <summary>
    /// 排序表达式
    /// a.id asc
    /// </summary>
    public string? OrderBy
    {
        get
        {
            var orderBy = !string.IsNullOrEmpty(OrderByColumn) ? $"{OrderByColumn.ToUnderScoreCase()} {(IsAscending ? "ASC" : "DESC")}" : "";
            return orderBy;
        }
    }

}
